import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:travel/utils/colors.dart';
import 'package:travel/utils/radian.dart';
import 'package:travel/utils/styles.dart';
import 'package:travel/utils/tools.dart';
import 'package:travel/screen/flutter_screenutil.dart';

class SignController extends GetxController {
  RxString sign = ''.obs;
}

class SignView extends GetView<SignController> {
  const SignView({super.key});

  @override
  Widget build(BuildContext context) {
    return Obx(() => Scaffold(
          backgroundColor: ColorsUtils.backgroundColor,
          appBar: AppBar(
            automaticallyImplyLeading: true,
            leading: InkWell(
              onTap: Get.back,
              child: Icon(
                Icons.arrow_back_ios,
                color: ColorsUtils.parseColorFromHexString(ColorsUtils.color3333),
                size: 20.w,
              ),
            ),
            leadingWidth: 40.w,
          ),
          body: SingleChildScrollView(
            padding: EdgeInsets.all(20.w),
            child: Column(
              children: [
                Container(
                  padding: EdgeInsets.only(top: 15.h),
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '个性签名',
                    style:
                        StylesUtils.customTextStyle(color: ColorsUtils.color3333, fontSize: 18.sp),
                  ),
                ),
                Container(
                    margin: EdgeInsets.only(top: 20.h),
                    padding: EdgeInsets.all(10.w),
                    alignment: Alignment.centerLeft,
                    child: TextField(
                      controller: ToolsUtils.editingController(controller.sign.value),
                      cursorWidth: 2.w,
                      cursorRadius: const Radius.circular(2),
                      cursorHeight: 15.h,
                      cursorColor: ColorsUtils.parseColorFromHexString(ColorsUtils.color3333),
                      style: StylesUtils.customTextStyle(
                          fontSize: 15.sp, color: ColorsUtils.color3333),
                      keyboardType: TextInputType.multiline,
                      maxLength: 200,
                      maxLengthEnforcement: MaxLengthEnforcement.enforced,
                      autofocus: false,
                      maxLines: 30,
                      minLines: 10,
                      textAlign: TextAlign.left,
                      textInputAction: TextInputAction.none,
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        focusedBorder: InputBorder.none,
                        hintText: '简单自我介绍，让你更受欢迎',
                        contentPadding: EdgeInsets.symmetric(horizontal: 15.w),
                        hintStyle: StylesUtils.customTextStyle(
                          color: ColorsUtils.color9999,
                        ),
                        isDense: false,
                        isCollapsed: false,
                        suffixIcon: IconButton(
                            onPressed: () {
                              controller.sign.value = '';
                            },
                            icon: Icon(
                              Icons.close_sharp,
                              size: 12,
                              color: ColorsUtils.parseColorFromHexString(ColorsUtils.color9999),
                            )),
                        suffixIconConstraints: BoxConstraints.expand(width: 18.w, height: 18.h),
                        constraints: BoxConstraints(maxHeight: 38.h),
                      ),
                      buildCounter: (
                        BuildContext context, {
                        required int currentLength,
                        required int? maxLength,
                        required bool isFocused,
                      }) {
                        return Row(
                          mainAxisAlignment: MainAxisAlignment.end,
                          children: <Widget>[
                            Text(
                              '$currentLength',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.colorD900, fontSize: 12.sp),
                            ),
                            Text(
                              '/$maxLength字',
                              style: StylesUtils.customTextStyle(
                                  color: ColorsUtils.color9999, fontSize: 12.sp),
                            ),
                          ],
                        );
                      },
                      onChanged: (String keyword) {
                        controller.sign.value = keyword;
                      },
                    )),
                Container(
                  height: 45.h,
                  margin: EdgeInsets.only(top: 30.h),
                  decoration: BoxDecoration(
                      borderRadius: BorderRadius.circular(10.w),
                      gradient: LinearGradient(colors: [
                        ColorsUtils.rgba(52, 120, 246, 1),
                        ColorsUtils.rgba(2, 167, 240, 1)
                      ], stops: const [
                        0,
                        0.99
                      ], transform: GradientRotation(RadianUtils.angleToRadian(90)))),
                  alignment: Alignment.center,
                  child: Text(
                    '保存',
                    style: StylesUtils.customTextStyle(fontSize: 16.sp),
                  ),
                )
              ],
            ),
          ),
        ));
  }
}
